<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>

    <div class="article-intro" id="content">

        <h1>JavaScript <span class="color_h1"> 比较</span> 和<span class="color_h1"> 逻辑运算符</span>
        </h1>
        <hr>
        <p class="intro">比较和逻辑运算符用于测试 <em>true</em> 或者
            <em>false</em>。
        </p>
        <hr>
        <h2>比较运算符</h2>
        <p>比较运算符在逻辑语句中使用，以测定变量或值是否相等。</p>
        <p给定<strong> x=5，下面的表格解释了比较运算符：<p></p>

            <table class="reference ">
                <tbody>
                    <tr>
                        <th width="15%" align="left">运算符</th>
                        <th width="40%" align="left">描述</th>
                        <th width="18%" align="left">比较</th>
                        <th width="17%" align="left">返回值</th>
                        <th width="10%" align="left">实例</th>
                    </tr>
                    <tr style="background-color:#ffffff">
                        <td valign="top" rowspan="2">==</td>
                        <td valign="top" rowspan="2">等于</td>
                        <td valign="top">x==8</td>
                        <td valign="top"><em>false</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison1">实例 »</a></td>
                    </tr>
                    <tr style="background-color:#ffffff">
                        <td valign="top">x==5</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison2">实例 »</a></td>
                    </tr>
                    <tr class="fixzebra">
                        <td valign="top" rowspan="2">===</td>
                        <td valign="top" rowspan="2">绝对等于（值和类型均相等）</td>
                        <td valign="top">x==="5"</td>
                        <td valign="top"><em>false</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison3">实例 »</a></td>
                    </tr>
                    <tr class="fixzebra">
                        <td valign="top">x===5</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison4">实例 »</a></td>
                    </tr>
                    <tr>
                        <td valign="top">!=</td>
                        <td valign="top">&nbsp;不等于</td>
                        <td valign="top">x!=8</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison5">实例 »</a></td>
                    </tr>
                    <tr>
                        <td valign="top" rowspan="2">!==</td>
                        <td valign="top" rowspan="2">&nbsp;不绝对等于（值和类型有一个不相等，或两个都不相等）</td>
                        <td valign="top">x!=="5"</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison6">实例 »</a></td>
                    </tr>
                    <tr class="fixzebra">
                        <td valign="top">x!==5</td>
                        <td valign="top"><em>false</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison7">实例 »</a></td>
                    </tr>
                    <tr style="background-color:#ffffff">
                        <td valign="top">&gt;</td>
                        <td valign="top">&nbsp;大于</td>
                        <td valign="top">x&gt;8</td>
                        <td valign="top"><em>false</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison8">实例 »</a></td>
                    </tr>
                    <tr class="fixzebra">
                        <td valign="top">&lt;</td>
                        <td valign="top">&nbsp;小于</td>
                        <td valign="top">x&lt;8</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison9">实例 »</a></td>
                    </tr>
                    <tr style="background-color:#ffffff">
                        <td valign="top">&gt;=</td>
                        <td valign="top">&nbsp;大于或等于</td>
                        <td valign="top">x&gt;=8</td>
                        <td valign="top"><em>false</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison10">实例 »</a></td>
                    </tr>
                    <tr class="fixzebra">
                        <td valign="top">&lt;=</td>
                        <td valign="top">&nbsp;小于或等于</td>
                        <td valign="top">x&lt;=8</td>
                        <td valign="top"><em>true</em></td>
                        <td valign="top"><a target="_blank" class="tryitbtn"
                                style="float:right;width:55px;padding-top:0px;padding-bottom:1px"
                                href="/try/try.php?filename=tryjs_comparison11">实例 »</a></td>
                    </tr>
                </tbody>
            </table>
            <br>
            <hr>
            <h2>如何使用</h2>
            <p>可以在条件语句中使用比较运算符对值进行比较，然后根据结果来采取行动：</p>

            <div class="code notranslate">
                <div>
                    if (age&lt;18) x="Too young";</div>
            </div>

            <p>您将在本教程的下一节中学习更多有关条件语句的知识。</p>
            <hr>
            <h2>逻辑运算符</h2>
            <p>逻辑运算符用于测定变量或值之间的逻辑。
            </p>
            <p>给定 x=6 以及 y=3，下表解释了逻辑运算符： </p>

            <table class="reference notranslate">
                <tbody>
                    <tr>
                        <th width="15%" align="left">运算符</th>
                        <th width="45%" align="left">描述</th>
                        <th width="40%" align="left">例子</th>
                    </tr>
                    <tr>
                        <td valign="top">&amp;&amp;</td>
                        <td valign="top">and</td>
                        <td valign="top"> (x &lt; 10 &amp;&amp; y &gt; 1) 为 true</td>
                    </tr>
                    <tr>
                        <td valign="top">||</td>
                        <td valign="top">or</td>
                        <td valign="top">(x==5 || y==5) 为 false</td>
                    </tr>
                    <tr>
                        <td valign="top">!</td>
                        <td valign="top">not</td>
                        <td valign="top"> !(x==y) 为 true</td>
                    </tr>
                </tbody>
            </table>
            <br>
            <hr>
            <h2>条件运算符</h2>
            <p>JavaScript 还包含了基于某些条件对变量进行赋值的条件运算符。</p>
            <h3>语法</h3>

            <div class="code notranslate">
                <div>
                    <em>variablename</em>=(<em>condition</em>)?<em>value1</em>:<em>value2</em>&nbsp;
                </div>
            </div>

            <h3>例子</h3>
            <div class="example">
                <h2 class="example">实例</h2>
                <p class="example">如果变量 age 中的值小于 18，则向变量 voteable 赋值 "年龄太小"，否则赋值 "年龄已达到"。</p>
                <div class="example_code">
                    <div class="hl-main"><span class="hl-identifier">voteable</span><span class="hl-code">=</span><span
                            class="hl-brackets">(</span><span class="hl-identifier">age</span><span
                            class="hl-code">&lt;</span><span class="hl-number">18</span><span
                            class="hl-brackets">)</span><span class="hl-code">?</span><span
                            class="hl-quotes">"</span><span class="hl-string">年龄太小</span><span
                            class="hl-quotes">"</span><span class="hl-code">:</span><span
                            class="hl-quotes">"</span><span class="hl-string">年龄已达到</span><span
                            class="hl-quotes">"</span><span class="hl-code">;</span></div>
                    <button class="copy-code-button" type="button"
                        data-clipboard-text="voteable=(age<18)?&quot;年龄太小&quot;:&quot;年龄已达到&quot;;"></button>
                </div><br><a target="_blank" class="tryitbtn" href="/try/try.php?filename=tryjs_comparison">尝试一下 »</a>
            </div> <!-- 其他扩展 -->

        </p给定<strong>
    </div>

</body>

</html>